package com.yc.psychologicalconsultant.utils;

import org.springframework.util.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author YC
 * @version 1.0
 */
public class ValidatorUtil {
    private static final Pattern mobile_pattern = Pattern.compile("^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\\d{8}$");
    private static final Pattern email_pattern = Pattern.compile("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$");

    // 检验邮箱
    public static boolean isEmail(String email) {
        if (!StringUtils.hasText(email)) return false;

        Matcher matcher = email_pattern.matcher(email);
        return matcher.matches();
    }

    // 检验手机号
    public static boolean isMobile(String mobile) {
        if (!StringUtils.hasText(mobile)) return false;

        Matcher matcher = mobile_pattern.matcher(mobile);
        return matcher.matches();
    }
}
